@extends('default.layouts.personalPublic')
@section('title', '个人账户中心')
@section('headcss')
    @parent
    <link rel="stylesheet" href="{{asset('/default/css/personal/welcome.css')}}">
    <link rel="stylesheet" href="{{asset('/default/css/personal/resumeRefresh.css')}}">
    <link rel="stylesheet" type="text/css" href="{{asset('/vendor/webuploader/dist/webuploader_img.css')}}">

@endsection
@section('rightcon')
    <div class="right">

        <div class="rightContain">
            <div class="headPic">
                <div class="pic" id="pic">
                    <span class="editavatar">修改头像</span>
                    <img src="{{$resumeInfo->avatar}}"/>
                </div>
            </div>
            <div class="detailRight">
                <div class="detailUp">
                    <p>
                        <span class="greet">@if(date('H') > 11) 下午好， @else 上午好， @endif{{str_limit($resumeInfo->name,8)}}！</span>
                        <a class="mobile" href="{{url('personal/set_account')}}"><i></i>{{$user->mobile}}</a>
                        <a class="email" href="{{url('personal/set_account')}}"><i></i>{{$user->email}}</a>
                        <a class="qq" href="{{url('personal/set_account')}}"><i class="qqPic"></i><span
                                    class="bqq">绑定QQ</span></a>
                        <a class="wx" href="{{url('personal/set_account')}}"><i class="wxPic"></i><span
                                    class="bwx">绑定微信</span></a>
                    </p>
                </div>
                <ul class="detailDown">
                    <li class="one">
                        <a href="{{url('personal/resume_mange')}}">
                            <dl>
                                @if($resumeInfo->percentage < 80)
                                    <dt class="percent">{{$resumeInfo->percentage}}%</dt>
                                @else
                                    <dt class="percent2">{{$resumeInfo->percentage}}%</dt>
                                @endif
                                <dd>简历完善度</dd>
                            </dl>
                        </a>
                    </li>
                    <li>
                        <a href="{{url('personal/privacy')}}">
                            <dl>
                                @if($resumeInfo->resume_status == 1)
                                    <dt class="lock publock"></dt>
                                    <dd>完全公开</dd>
                                @elseif($resumeInfo->resume_status == 2)
                                    <dt class="lock"></dt>
                                    <dd>不公开</dd>
                                @elseif($resumeInfo->resume_status == 3)
                                    <dt class="lock"></dt>
                                    <dd>完全保密</dd>
                                @else
                                    <dt class="lock"></dt>
                                    <dd>审核不通过</dd>
                                @endif
                            </dl>
                        </a>
                    </li>
                    <li>
                        <a href="{{url('personal/interview')}}">
                            <dl>
                                <dt>{{$resumeInfo->interviewCount}}</dt>
                                <dd>面试通知</dd>
                            </dl>
                        </a>
                    </li>
                    <li>
                        <a href="{{url('personal/resume_send')}}">
                            <dl>
                                <dt>{{$resumeInfo->resumeSendCount}}</dt>
                                <dd>简历投递记录</dd>
                            </dl>
                        </a>
                    </li>
                    <li>
                        <a href="{{url('personal/browse_resume')}}">
                            <dl>
                                <dt>{{$resumeInfo->browseResumeCount}}</dt>
                                <dd>浏览记录</dd>
                            </dl>
                        </a>
                    </li>
                    <li class="list">
                        <a href="{{url('personal/resume_mange')}}">
                            <dl>
                                <dt>{{$resumeInfo->buyResumeCount}}</dt>
                                <dd>简历被下载</dd>
                            </dl>
                        </a>
                    </li>
                </ul>
            </div>
        </div>
        <div class="rightContainTwo">
            {{--求职意向--}}
            <div class="content">
                <div class="contentLeft">
                    <ul>
                        <li>简历状态：<span class="review"
                                       @if($resumeInfo->resume_status == 1)style="color:#61AF00" @endif>{{$resumeInfo->status}}</span>
                        </li>
                        <li>求职意向：{{$resumeInfo->intentionjobs}}</li>
                        <li>期望月薪：@if($resumeInfo->expectedsalary == 1)面议@else{{$resumeInfo->expectedsalary}}@endif</li>
                        <li>最近工作：@if(!empty($resumeInfo->post)){{$resumeInfo->post}}
                            <b>|</b>{{$resumeInfo->company}}@else未填写@endif</li>
                        <li>求职状态：{{$resumeInfo->job_status_val}}</li>
                    </ul>
                </div>
                <div class="contentRight">
                    <div class="reflash">
                        <div class="reflashUp">
                            <a @if(empty($resumeInfo->id))
                               href="{{url('personal/warmtips')}}"
                            @else
                                {{--onclick="keep_screen('#rightMain')"--}}
                                    @endif
                            >刷新简历</a></div>
                        <div class="reflashDown">{{$resumeInfo->updatetime}}</div>
                    </div>
                    <div class="modify">
                        <div class="modifyUp"><a href="{{url('personal/resume_mange')}}">修改简历</a></div>
                        <div class="modifyDown">{{$resumeInfo->updatetime}}</div>
                    </div>
                </div>
            </div>
        </div>

        {{--合适的岗位--}}
        <div class="modifyJob">
            <span class="modifyText">可能适合您的岗位</span>
            <a class="modifySide" href="{{url('personal/resume_mange')}}">修改求职意向</a>
            <span class="more"><a href="{{url('personal/recommended_post')}}">更多+</a> </span>
        </div>
        {{--岗位列表--}}
        @if(count($similarJobs) > 0)
            <div class="propertyJob">
                <ul>
                    @foreach($similarJobs as $v)
                        <li>
                            <a href="{{url('jobinfo_'.idEncryption($v->id).'.html')}}" target="_blank">
                                <dl>
                                    <dt>{{str_limit($v->job_title,28)}}</dt>
                                    <dd>{{str_limit($v->company_name,28)}}</dd>
                                    <dd><span class="slary">@if(empty($v->salary_above))面试@else{{$v->salary_above}}
                                            ~{{$v->salary_below}}元/月@endif</span></dd>
                                </dl>
                            </a>
                        </li>
                    @endforeach
                </ul>
            </div>
        @endif
        {{--更多工作--}}
        <div class="moreJob"><a href="{{url('personal/recommended_post')}}">更多推荐职位 </a></div>
    </div>

    {{--弹出刷新简历--}}
    <div class="rightMain keepMain" id="rightMain">
        {{--简历错误信息--}}
        @if(count($errors)>0)
            <div class="errors">
                <ul>
                    @if(is_object($errors))
                        @foreach($errors->all() as $error)
                            <li><span>{{$error}}</span></li>
                        @endforeach
                    @else
                        <li><span>{{$error}}</span></li>
                    @endif
                </ul>
            </div>
        @endif
    </div>
@endsection
@section('footerjs')
    @parent
    <script type="text/javascript" src="{{asset('/default/js/jquery/jquery.form.js')}}"></script>
    <script type="text/javascript" src="{{Resources::jsOption(['work_year'])}}"></script>
    <script type="text/javascript" src="{{Resources::jsOption(['job_status'])}}"></script>
    <script type="text/javascript" src="{{asset('/default/js/jquery/jquery.validate.extend.js')}}"></script>
    <script>
        $(function(){
            @if(auth()->guard('personal')->check())
                //检查个人的cookie是不是存在
                if(getCookie('personal_cookie') == null || getCookie('personal_cookie') == ''){
                    $.get("personal/set_personal_cookie", function(data){
                        if(data.status == '1'){
                            setCookie('personal_cookie', 1,1 / 24);
                            resume_refresh();
                        }else if(data.status == '2'){
                            setCookie('personal_cookie', 1,1 / 24);
                        }
                    });
                }
            @endif
            $('#welcome').addClass('on');
            //刷新简历
            $(".reflashUp a").click(function(){
                resume_refresh();
            });
        });
        /**
         * 刷新简历
         */
        function resume_refresh(){
            var dopen = layer.open({
                type: 1,
                title: "刷新简历",
                move: false,
                skin: 'layui-layer-rim', //加上边框
                area: ['840px', '600px'], //宽高
                content: '<div class="rightMain" style="padding:0px;"><div class="jobInfo">' +
                '<div class="information"><span>您的简历最近一次更新日期是：{{$resumeInfo->refreshtime}}</span></div>' +
                '<form name="refreshForm" onSubmit="return false" id="refreshForm" method="post" >{{csrf_field()}}' +
                '<input name="id" type="hidden" value="{{$resumeInfo->id}}" />' +
                '<input name="requestajax" type="hidden" value="1" />' +
                '<dl><dt><span class="caption">工作经验</span></dt><dd><input id="work_year" name="work_year" type="hidden" value="">' +
                '<div id="work_year_select" class="select" style="width: 160px;"><span><a></a></span><i></i></div></dd><dd class="errinfo"></dd></dl>' +
                '<dl><dt><span class="caption">手机号码</span><span class="asterisk">*</span></dt><dd>' +
                '<input type="text" name="mobile" id="mobile" value="{{ $resumeInfo->mobile  or ''}}" style="width: 130px;" placeholder="请输入手机号码" tip="请输入手机号码"/></dd><dd class="errinfo"></dd></dl>' +
                '<dl><dt><span class="caption">求职状态</span><span class="asterisk">*</span></dt><dd><input id="job_status" name="job_status" type="hidden" value="">' +
                '<div id="job_status_select" class="select" style="width:200px;"><span><a></a></span><i></i></div></dd><dd class="errinfo"></dd></dl>' +
                '<dl><dt><span class="caption">电子邮箱</span><span class="asterisk">*</span></dt><dd>' +
                '<input type="text" name="email" id="email" value="{{ $resumeInfo->email  or '' }}" placeholder="请输入电子邮箱" tip="请输入电子邮箱"/></dd><dd class="errinfo"></dd></dl>' +
                '<dl><dt><span class="caption">QQ号码</span></dt><dd>' +
                '<input type="text" name="qq" id="qq" value="{{  $resumeInfo->qq  or ''}}" style="width: 150px;" placeholder="请输入QQ号码" tip="请输入QQ号码"/></dd><dd class="errinfo"></dd></dl>' +
                '<dl><dt><span class="caption">通讯地址</span></dt><dd>' +
                '<input type="text" name="address" id="address" value="{{  $resumeInfo->address or '' }}" style="width: 360px;" placeholder="请输入通讯地址" tip="请输入通讯地址"/></dd><dd class="errinfo"></dd></dl>' +
                '<dl><dt></dt><dd><span><input type="radio" name="uptype" id="uptype1" class="radios" checked value="1"/><label for="uptype1">刷新简历并更新联系方式</label>' +
                '</span><span class="mLeftTen"><input type="radio" name="uptype" id="uptype2" class="radios" value="2"/><label for="uptype2">只更新联系方式</label></span></dd></dl>' +
                '<dl style="margin-top:25px;"><dt></dt><dd><input name="sub" class="subs btn" type="submit" value="马上刷新"></dd>' +
                '<dd><a class="subs btn cancel" href="javascript:layer.closeAll()">以后再说</a></dd></dl></form>' +
                '</div></div>'
            });
            $("#refreshForm").find("#work_year").select({
                defaults: null,//默认按索引选中null为不选
                defaultFill: [{"value": '', "text": "请选择"}],//当defaults为null时,填空使用这个
                optionData: option_work_year,
                selected: '{{$resumeInfo->work_year}}'
            });
            $("#refreshForm").find("#job_status").select({
                defaults: null,//默认按索引选中null为不选
                defaultFill: [{"value": '', "text": "请选择"}],//当defaults为null时,填空使用这个
                optionData: option_job_status,
                selected: '{{$resumeInfo->job_status}}'
            });

            //个人会员手机号码验证
            $.validator.addMethod("checkMobile", function(value, element, param){
                var regu = /(^1[3-9]{1}[0-9]{9}$)/g;
                if(regu.test(value)){
                    return true;
                }else{
                    return false;
                }
            }, "请输入正确的手机号码");

            //个人QQ号码验证
            $.validator.addMethod("checkQQ", function(value, element, param){
                if(value != ''){
                    var regu = /(^[1-9]{1}[0-9]{4,15})$/g;
                    if(regu.test(value)){
                        return true;
                    }else{
                        return false;
                    }
                }else{
                    return true;
                }
            }, "请输入正确的QQ号码");

            //表单验证 使用jQuery Validate 插件进行验证
            $('#refreshForm').validate({
                //指定使用什么标签标记错误。
                errorElement: "span",
                //一个函数，可以自定义错误放到哪里。
                errorPlacement: function(error, element){
                    $(element).parents('dl').find(".errinfo").append(error);
                },
                //自定义错误消息
                tipPlacement: function(element, tip){
                    $(element).parents('dl').find(".errinfo").append(tip);
                },
                //通过验证后执行的函数
                success: function(label){
                    if(label.parents('dl').find('dd input').val() != ''){
                        label.text('ok!').addClass('success');
                    }
                },
                //未验证后执行的函数
                highlight: function(element, errorClass){
                    $(element).closest("dl").find("dd.errinfo").find('span').removeClass('success');
                },
                ignore: "",
                //js上面添加验证规则
                rules: {
                    mobile: {
                        required: true,
                        minlength: 11,
                        checkMobile: true //期望的是true,如果为false则展示提示信息
                    },
                    job_status: {
                        required: true
                    },
                    email: {
                        required: true,
                        email: true
                    },
                    qq: {
                        checkQQ: true                            //期望的是true,如果为false则展示提示信息
                    }
                },
                //错误信息提示修改
                messages: {
                    mobile: {
                        required: "请输入手机号码",
                        minlength: "手机号码长度必须是11位数字"
                    },
                    job_status: {
                        required: "请选择求职状态"
                    },
                    email: {
                        required: "邮箱必须填写",
                        email: "请输入一个正确的邮箱"
                    }
                },
                submitHandler: function(form){
                    var queryString = $('#refreshForm').formSerialize();
                    $.ajax({
                        url: '/personal/post_resume_refresh',
                        dataType: "json",
                        data: queryString,
                        type: "POST",
                        beforeSend: function(){
                            $('#refreshForm').find('.subs').val('请稍候');
                            $('#refreshForm').find('.subs').attr('disabled', true);
                            $('#refreshForm').find('.subs').attr('readonly', true);
                        },
                        success: function(data){
                            if(data.status == 0){
                                layer.msg(data.msg, {icon: 6, time: 1500});
                                location = '{{url('personal/welcome')}}';
                            }else{
                                layer.msg(data.msg, {time: 2000});
                            }
                        },
                        error: function(data){
                            var msgErr = '';
                            var errors = $.parseJSON(data.responseText);
                            $.each(errors, function(index, value){
                                msgErr += value + ";<br>";
                            });
                            layer.msg(msgErr);
                        },
                        complete: function(){
                            $('#refreshForm').find('.subs').val('确定更新');
                            $('#refreshForm').find('.subs').removeAttr('disabled');
                            $('#refreshForm').find('.subs').removeAttr('readonly');
                        }
                    });
                }
            });

        }
    </script>
    <script type="text/javascript">
        $(function(){
            $('.right').find('.rightContain').find('.pic').hover(function(){
                $(this).find('.editavatar').show();
            }, function(){
                $(this).find('.editavatar').hide();
            });
            uploadAvatar('#pic');
        });
        //上传头像
        function uploadAvatar(upavatar){
            var uploaderavatar = WebUploader.create({
                auto: true,
                formData: {
                    _token: "{{csrf_token()}}"
                },
                duplicate: true,
                // swf文件路径
                swf: BASE_URL + 'vendor/webuploader/dist/Uploader.swf',
                // 文件接收服务端。
                server: "{{asset('/personal/uploadavatar')}}",
                // 选择文件的按钮。可选。
                // 内部根据当前运行是创建，可能是input元素，也可能是flash.
                pick: {
                    id: upavatar,
                    multiple: false
                },
                compress: {
                    width: 200,
                    height: 200,
                    // 图片质量，只有type为`image/jpeg`的时候才有效。
                    //quality: 100,
                    // 是否允许放大，如果想要生成小图的时候不失真，此选项应该设置为false.
                    allowMagnify: true,
                    // 是否允许裁剪。
                    crop: true,
                    compressSize: 0,
                    noCompressIfLarger: false
                },
                accept: {
                    title: 'Images',
                    extensions: 'gif,jpg,jpeg,bmp,png',
                    mimeTypes: '.gif,.jpg,.jpeg,.bmp,.png'
                },
                // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
                fileSingleSizeLimit: 2000 * 1024
            });
            //上传文件出错时
            uploaderavatar.on('error', function(file){
                if(file == 'F_EXCEED_SIZE'){
                    layer.msg('文件大小不能超过2M！', {time: 1200});
                }
                if(file == 'F_DUPLICATE'){
                    layer.msg('此文件已经存在队列当中，不能重复上传！', {time: 1200});
                }
                if(file == 'Q_EXCEED_NUM_LIMIT'){
                    layer.msg('你已经上传了文件！', {time: 1200});
                }
                if(file == 'Q_TYPE_DENIED'){
                    layer.msg('文件类型不匹配，请重新上传！', {time: 1200});
                }
            });
            uploaderavatar.on('uploadSuccess', function(file, response){
                if(response.status == 200){
                    $(upavatar).find('img').attr("src", response.url);
                }else if(response.error == 404){
                    layer.msg(response.info);
                    location = '/personal/my_resume';
                }else{
                    layer.msg(response.info);
                }
            });
        }
    </script>
    <script type="text/javascript" src="{{asset('/vendor/webuploader/dist/webuploader.min.js')}}"></script>
    <script type="text/javascript" src="{{asset('/default/js/personal/welcome.js')}}"></script>
@endsection